import { defineStore } from "pinia";
import { computed, ref } from "vue";

export const useGood=defineStore('good',()=>{
    const goodsList=ref([
        {name:'商品1',price:100},
        {name:'商品2',price:102},
    ])
    //添加商品
    const goodsAdd=(goodsObj)=>{
        goodsList.value.push(goodsObj)
    }
    //过滤
    const filterGoodsList=computed(()=>{
        return goodsList.value.filter(item=>{
            return item.price>=100
        })
    })
    return {
        goodsList,
        goodsAdd,
        filterGoodsList
    }
},
{
    persist:true
})